package com.gongj.lookupMethod;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public abstract class TestLookupMethod {

	public abstract Fruit getBean();

	/**
	 * 这个方法的创建不会对于 LookupMethod 的覆盖不会有任何影响
	 * 这个参数Spring并不会去处理它
	 * 影响的地方也就是在 createBean() 里的 prepareMethodOverrides() 方法了，
	 * overloaded 属性不会被设置为 false 了。

	 AbstractBeanDefinition#prepareMethodOverride
	 protected void prepareMethodOverride(MethodOverride mo) throws BeanDefinitionValidationException {
	 // 获取对应类中对应方法的个数
	 int count = ClassUtils.getMethodCountForName(getBeanClass(), mo.getMethodName());
	 if (count == 0) {
	 throw new BeanDefinitionValidationException(
	 "Invalid method override: no method with name '" + mo.getMethodName() +
	 "' on class [" + getBeanClassName() + "]");
	 }
	 else if (count == 1) {
	 // Mark override as not overloaded, to avoid the overhead of arg type checking.
	 //标记 overloaded 暂未被覆盖 避免参数类型检查的开销
	 mo.setOverloaded(false);
	 }
	 }
	 */
	public abstract Fruit getBean(String str);

	public void start(){
		this.getBean().eat();
	}


	public static void main(String[] args) {
		ClassPathXmlApplicationContext context =
				new ClassPathXmlApplicationContext("lookup-method.xml");
		TestLookupMethod bean =(TestLookupMethod) context.getBean("lookupMethod");
		bean.start();
	}
}
